<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>我的工作台</title>
<script type="text/javascript" src="${rc.contextPath}/common/js/jquery/jquery-1.9.1.js"></script>
<script type="text/javascript" src="${rc.contextPath}/assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="${rc.contextPath}/assets/js/date-time/bootstrap-datepicker.min.js"></script>
<script type="text/javascript" src="${rc.contextPath}/common/js/common.js"></script>
<script type="text/javascript" src="${rc.contextPath}/assets/js/bootstrap-table.js"></script>
<script type="text/javascript" src="${rc.contextPath}/assets/js/bootstrap-table-zh-CN.js"></script>
<link href="${rc.contextPath}/assets/js/bootstrap-table.css"	rel="stylesheet" />
<link rel="stylesheet" href="${rc.contextPath}/assets/css/ace.min.css" />
<link href="${rc.contextPath}/assets/js/bootstrap-3.3.7.css"	rel="stylesheet" />
<script src="${rc.contextPath}/common/js/market/service/customer_deal_detail.js"></script>
<script src="${rc.contextPath}/assets/js/bootstrap-select.js"></script>
<link href="${rc.contextPath}/assets/js/bootstrap-select.css"rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function(){
	
	//获取每个table的条数
	/* function findDept(){
		var url = "/customerManage/getAllNotAcceptCustom";
		$.post(
				url,
				{customerType: $("#customerTypeId").val();},
				function(data) {
					var expressCompany = data.;
					
				}
				
				);
	} */
	
    $("#summary_table").bootstrapTable({
    			sidePagination: "server", //服务端处理分页
    			method: 'post',
  				contentType: "application/x-www-form-urlencoded",
                url: '/customerManage/getAllNotAcceptCustom',
                dataType: "json",
                pagination: true, //分页
                singleSelect: false,
                search: true, //显示搜索框
                queryParams: paginationParam,
                
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                	$("#summaryspan").html(totalRows);
                    return '显示第 ' + pageFrom + ' 到第 ' + pageTo + ' 条记录，总共 ' + totalRows + ' 条记录';
                },
      
		columns : [ {
				title : '会员号',
				align : 'center',
				valign: 'middle',
				width : 50,
				formatter: function(value, row, index) { 
		        	if(row.customState==1){
		        		return '<a href="#" onclick=goCustomerDetails(\"'+row.customId+'\")>'+row.customId+'</a>';
		        	}else{
		        		return '<font color="gray">'+row.customId+'</font>';
		        	}
		        }
			},

			{
				title : '注册日期',
				align : 'center',
				valign: 'middle',
				width : 120,
				formatter: function(value, row, index) { 
		        	if(row.customState==1){
		        		return row.addTime;
		        	}else{
		        		return '';
		        	}
		        }
			},

			{
				title : '接收日期',
				align : 'center',
				valign: 'middle',
				width : 50,
				formatter: function(value, row, index) { 
		        	if(row.customState==1){
		        		return row.createTime;
		        	}else{
		        		return '';
		        	}
		        }
			},

			{
				title : '所属分公司',
				align : 'center',
				valign: 'middle',
				width : 50,
				formatter: function(value, row, index) { 
		        	if(row.customState==1){
		        		return row.companyAbb;
		        	}else{
		        		return '';
		        	}
		        }
			},

			{
				title : '所属地区',
				align : 'center',
				valign: 'middle',
				width : 50,
				formatter: function(value, row, index) { 
		        	if(row.customState==1){
		        		return row.areaName;
		        	}else{
		        		return '';
		        	}
		        }
			},
			
			{title: '所属人', 
                align: 'center', 
                valign: 'middle',
                width: 50, 
                formatter: function(value, row, index) { 
		        	if(row.customState==1){
		        		return row.empName;
		        	}else{
		        		return '';
		        	}
		        }
             },
             
             {title: '注册来源', 
                 align: 'center', 
                 valign: 'middle',
                 width: 50, 
             	 formatter: function(value, row, index) { 
		        	if(row.customState==1){
		        		return '网站';
		        	}else{
		        		return '';
		        	}
		         }
              },
              
              {title: '接收状态', 
                  align: 'center', 
                  valign: 'middle',
                  width: 50, 
                  formatter: function(value, row, index) { 
                	if(row.customState==1){
                		return "已接收";
                	}else if(row.customState==2){
                		return "拒绝";
                	}else if(row.customState==0){
                		return "未接收";
                	}else{
                		return "未接收";
                	}
                  	
                  	} 
               },
               
               {title: '操作', 
                   align: 'center', 
                   valign: 'middle',
                   width: 50, 
	               formatter: function(value, row, index) { 
	            	   console.log(index);
	            	   var obj = row[index];
	            	   console.log(row);
	            	   console.log(obj);
			        	if(row.customState==1){
			        		return '<a href="#myModal" onclick=markCusId(\"'+row.customId+'\");setCompanyId(\"'+row.companyId+'\",\"'+row.companyAbb+'\");findDept(); data-toggle="modal" >调配</a>';
			        	}else{
			        		if('$!{currentUser.ename}'==row.empName){
			        			return '<a href="#" onclick=accept(\"'+row.customId+'\")>接收</a>';
			        		}else{
			        			return '';
			        		}
			        	}
			         }		
               
                },
			]
		});
    
	
    $("#second_table").bootstrapTable({
		sidePagination: "server", //服务端处理分页
		method: 'post',
		contentType: "application/x-www-form-urlencoded",
		url: '/customerManage/getSecond',
        dataType: "json",
        pagination: true, //分页
        singleSelect: false,
        search: false, //显示搜索框
        queryParams: paginationParam,
        pageList: [10, 25, 50, 100, 200],
        
        formatShowingRows: function (pageFrom, pageTo, totalRows) {
        	$("#secondspan").html(totalRows);
            return '显示第 ' + pageFrom + ' 到第 ' + pageTo + ' 条记录，总共 ' + totalRows + ' 条记录';
        },
     
               columns : [ {
					title : '会员号',
					align : 'center',
					valign: 'middle',
					width : 50,
					formatter: function(value, row, index) {
						return '<a href="#" onclick=goCustomerDetails(\"'+row.cusId+'\")>'+row.cusId+'</a>';
				 	},
				},

				{
					title : '客户名称',
					align : 'center',
					valign: 'middle',
					width : 50,
					field : 'cname'
				},

				{
					title : '注册日期',
					align : 'center',
					valign: 'middle',
					width : 50,
					field : 'addTime'
				},

				{
					title : '最后联系时间',
					align : 'center',
					valign: 'middle',
					width : 50,
					field : 'create_time'
				},

				{
					title : '所属分公司',
					align : 'center',
					valign: 'middle',
					width : 50,
					field : 'companyAbb'
				},
				
				{title: '所属人', 
	               align: 'center', 
	               valign: 'middle',
	               width: 50, 
	               field :'ename'
	            },
				]
		});
	
	
    
	});
	
	function maketable(type){
		if(type==1){
			$("#summary_table").bootstrapTable('destroy');
			 $("#summary_table").bootstrapTable({
	    			sidePagination: "server", //服务端处理分页
	    			method: 'post',
	  				contentType: "application/x-www-form-urlencoded",
	                url: '/customerManage/getAllNotAcceptCustom',
	                dataType: "json",
	                pagination: true, //分页
	                singleSelect: false,
	                search: true, //显示搜索框
	                queryParams: paginationParam,
	                
	                formatShowingRows: function (pageFrom, pageTo, totalRows) {
	                	$("#summaryspan").html(totalRows);
	                    return '显示第 ' + pageFrom + ' 到第 ' + pageTo + ' 条记录，总共 ' + totalRows + ' 条记录';
	                },
	      
			columns : [ {
					title : '会员号',
					align : 'center',
					valign: 'middle',
					width : 50,
					formatter: function(value, row, index) { 
			        	if(row.customState==1){
			        		return '<a href="#" onclick=goCustomerDetails(\"'+row.customId+'\")>'+row.customId+'</a>';
			        	}else{
			        		return '<font color="gray">'+row.customId+'</font>';
			        	}
			        }
				},

				{
					title : '注册日期',
					align : 'center',
					valign: 'middle',
					width : 120,
					formatter: function(value, row, index) { 
			        	if(row.customState==1){
			        		return row.addTime;
			        	}else{
			        		return '';
			        	}
			        }
				},

				{
					title : '接收日期',
					align : 'center',
					valign: 'middle',
					width : 50,
					formatter: function(value, row, index) { 
			        	if(row.customState==1){
			        		return row.createTime;
			        	}else{
			        		return '';
			        	}
			        }
				},

				{
					title : '所属分公司',
					align : 'center',
					valign: 'middle',
					width : 50,
					formatter: function(value, row, index) { 
			        	if(row.customState==1){
			        		return row.companyAbb;
			        	}else{
			        		return '';
			        	}
			        }
				},

				{
					title : '所属地区',
					align : 'center',
					valign: 'middle',
					width : 50,
					formatter: function(value, row, index) { 
			        	if(row.customState==1){
			        		return row.areaName;
			        	}else{
			        		return '';
			        	}
			        }
				},
				
				{title: '所属人', 
	                align: 'center', 
	                valign: 'middle',
	                width: 50, 
	                formatter: function(value, row, index) { 
			        	if(row.customState==1){
			        		return row.empName;
			        	}else{
			        		return '';
			        	}
			        }
	             },
	             
	             {title: '注册来源', 
	                 align: 'center', 
	                 valign: 'middle',
	                 width: 50, 
	             	 formatter: function(value, row, index) { 
			        	if(row.customState==1){
			        		return '网站';
			        	}else{
			        		return '';
			        	}
			         }
	              },
	              
	              {title: '接收状态', 
	                  align: 'center', 
	                  valign: 'middle',
	                  width: 50, 
	                  formatter: function(value, row, index) { 
	                	if(row.customState==1){
	                		return "已接收";
	                	}else if(row.customState==2){
	                		return "拒绝";
	                	}else if(row.customState==0){
	                		return "未接收";
	                	}else{
	                		return "未接收";
	                	}
	                  	
	                  	} 
	               },
	               
	               {title: '操作', 
	                   align: 'center', 
	                   valign: 'middle',
	                   width: 50, 
		               formatter: function(value, row, index) { 
				        	if(row.customState==1){
				        		return '<a href="#myModal" onclick=markCusId(\"'+row.customId+'\");setCompanyId(\"'+row.companyId+'\",\"'+row.companyAbb+'\");findDept(); data-toggle="modal" >调配</a>';
				        	}else{
				        		if('$!{currentUser.ename}'==row.empName){
				        			return '<a href="#" onclick=accept(\"'+row.customId+'\")>接收</a>';
				        		}else{
				        			return '接收';
				        		}
				        	}
				         }		
	               
	                },
				]
			});
		
		}
		
		if(type==3){
			$("#region_table").bootstrapTable('destroy');
			$("#region_table").bootstrapTable({
	    	sidePagination: "server", //服务端处理分页
			method: 'post',
			contentType: "application/x-www-form-urlencoded",
			url: '/customerManage/getMindCustom',
	        dataType: "json",
	        singleSelect: false,
	        pagination: true, //分页
	        search: false, //显示搜索框
	        queryParams: paginationParam,
            
	        formatShowingRows: function (pageFrom, pageTo, totalRows) {
            	$("#regionspan").html(totalRows);
                return '显示第 ' + pageFrom + ' 到第 ' + pageTo + ' 条记录，总共 ' + totalRows + ' 条记录';
            },
	        
    		columns: [
					{title: '会员号', 
						align: 'center', 
						width: 50, 
						formatter: function(value, row, index) {
							return '<a href="#" onclick=goCustomerDetails(\"'+row.cusId+'\")>'+row.cusId+'</a>';
					 	},
						
					},
					{
						title : '客户名称',
						align : 'center',
						valign: 'middle',
						width : 150,
						field : 'cname',
					},

					{
						title : '意向商品',
						align : 'center',
						valign: 'middle',
						width : 50,
						field : 'goodsName',
					},

					{
						title : '预计消耗金额',
						align : 'center',
						valign: 'middle',
						width : 50,
						field : 'timeAmount',
					},

					{
						title : '预计消耗日期',
						align : 'center',
						valign: 'middle',
						width : 50,
						field : 'startVanishTime',
					},
					
					{title: '计划联系日期', 
		                align: 'center', 
		                valign: 'middle',
		                width: 50, 
		                field : 'endVanishTime',
		             },
		             
		             {title: '销售阶段', 
		                 align: 'center', 
		                 valign: 'middle',
		                 width: 50, 
		                 field : 'domainName',
		              },
		              
		              {title: '最后联系时间', 
		                  align: 'center', 
		                  valign: 'middle',
		                  width: 50, 
		                  field : 'dueTime',
		               },
    				]
			});
		}
		//待续费部分开始
		if(type==5){
			$("#waitcharge_table").bootstrapTable('destroy');
			$("#waitcharge_table").bootstrapTable({
				sidePagination: "server", //服务端处理分页
				method: 'post',
				contentType: "application/x-www-form-urlencoded",
				url: '/customerManage/getWaitCharge',
		        dataType: "json",
		        pagination: true, //分页
		        singleSelect: false,
		        search: false, //显示搜索框
		        queryParams: paginationParam,
	            pageList: [10, 25, 50, 100, 200],
		     
	            formatShowingRows: function (pageFrom, pageTo, totalRows) {
                	$("#waitchargespan").html(totalRows);
                    return '显示第 ' + pageFrom + ' 到第 ' + pageTo + ' 条记录，总共 ' + totalRows + ' 条记录';
                },
	            
				columns : [ {
						title : '会员号',
						align : 'center',
						valign: 'middle',
						width : 50,
						formatter: function(value, row, index) {
							return '<a href="#" onclick=goCustomerDetails(\"'+row.cusId+'\")>'+row.cusId+'</a>';
					 	},
					},

					{
						title : '客户名称',
						align : 'center',
						valign: 'middle',
						width : 50,
						field : 'cname',
					},

					{
						title : '最近到期商品',
						align : 'center',
						valign: 'middle',
						width : 50,
						formatter : function(value, row, index) {
							return '虚机';
						}
					},

					{
						title : '到期日期',
						align : 'center',
						valign: 'middle',
						width : 50,
						field : 'addTime'
					},

					{
						title : '所属分公司',
						align : 'center',
						valign: 'middle',
						width : 50,
						field : 'companyAbb'
					},
					
					{title: '所属人', 
		               align: 'center', 
		               valign: 'middle',
		               width: 50, 
		               field :'ename'
		            },
					]
				});
		}
		//保护期客户部分开始
		if(type==12){
			$("#protect_table").bootstrapTable('destroy');
			$("#protect_table").bootstrapTable({
						sidePagination: "server", //服务端处理分页
						method: 'post',
						contentType: "application/x-www-form-urlencoded",
						url: '/customerManage/getProtect',
				        dataType: "json",
				        pagination: true, //分页
				        search: false, //显示搜索框
				        queryParams: paginationParam,
			            
				        
				        formatShowingRows: function (pageFrom, pageTo, totalRows) {
		                	$("#protectspan").html(totalRows);
		                    return '显示第 ' + pageFrom + ' 到第 ' + pageTo + ' 条记录，总共 ' + totalRows + ' 条记录';
		                },
		     
		               columns : [ {
							title : '会员号',
							align : 'center',
							valign: 'middle',
							width : 50,
							formatter: function(value, row, index) {
								return '<a href="#" onclick=goCustomerDetails(\"'+row.cusId+'\")>'+row.cusId+'</a>';
						 	},
						},

						{
							title : '客户名称',
							align : 'center',
							valign: 'middle',
							width : 50,
							field : 'cname'
						},

						{
							title : '注册日期',
							align : 'center',
							valign: 'middle',
							width : 50,
							field : 'addTime'
						},

						{
							title : '最后联系时间',
							align : 'center',
							valign: 'middle',
							width : 50,
							field : 'create_time'
						},

						{
							title : '所属分公司',
							align : 'center',
							valign: 'middle',
							width : 50,
							field : 'companyAbb'
						},
						
						{title: '所属人', 
			               align: 'center', 
			               valign: 'middle',
			               width: 50, 
			               field:'ename'
			            },
						]
				});
		}
		//二次开发部分开始
		if(type==8){
			$("#second_table").bootstrapTable('destroy');
			$("#second_table").bootstrapTable({
				sidePagination: "server", //服务端处理分页
				method: 'post',
				contentType: "application/x-www-form-urlencoded",
				url: '/customerManage/getSecond',
		        dataType: "json",
		        pagination: true, //分页
		        singleSelect: false,
		        search: false, //显示搜索框
		        queryParams: paginationParam,
	            pageList: [10, 25, 50, 100, 200],
	            
	            formatShowingRows: function (pageFrom, pageTo, totalRows) {
                	$("#secondspan").html(totalRows);
                    return '显示第 ' + pageFrom + ' 到第 ' + pageTo + ' 条记录，总共 ' + totalRows + ' 条记录';
                },
		     
		               columns : [ {
							title : '会员号',
							align : 'center',
							valign: 'middle',
							width : 50,
							formatter: function(value, row, index) {
								return '<a href="#" onclick=goCustomerDetails(\"'+row.cusId+'\")>'+row.cusId+'</a>';
						 	},
						},

						{
							title : '客户名称',
							align : 'center',
							valign: 'middle',
							width : 50,
							field : 'cname'
						},

						{
							title : '注册日期',
							align : 'center',
							valign: 'middle',
							width : 50,
							field : 'addTime'
						},

						{
							title : '最后联系时间',
							align : 'center',
							valign: 'middle',
							width : 50,
							field : 'create_time'
						},

						{
							title : '所属分公司',
							align : 'center',
							valign: 'middle',
							width : 50,
							field : 'companyAbb'
						},
						
						{title: '所属人', 
			               align: 'center', 
			               valign: 'middle',
			               width: 50, 
			               field :'ename'
			            },
						]
				});
		}
	}
	
	//传入分页参数
	function paginationParam(params) {
		var type = $("#customerTypeId").val();
		if(type){
			type = type;
		}else{
			type = 1;
		}
	    return {
	    	customerType: type,
	        pageSize: params.limit,
	        pageNow: params.offset,
	        endAddTime:params.search
	    };
	};
	
	//点击后确认处于哪个标签页
	function tabclick(customerTypeId){
		$("#customerTypeId").val(customerTypeId);
		maketable(customerTypeId);
		
	};
	//给选中数据做标示
	function markCusId(b){
		$("#selectedCusId").val(b);
		console.log(b);
	}
	function accept(cusId){
		var cusIdStr = cusId;
		$.post(
				"/customerManage/acceptCustom",
				{
					"cusId": cusId,
				},
				function(data) {
					var result = eval(data);
					if(result == 0) {
						alert("超时未接收！该客户已流走！");
					}else{
						alert("成功接收！");
					}
					query($('#pageNow').val());
				}
			);
	}
	
	//校验申请调配数据 并根据不同选定内容跳转链接
	function checkApplyParam(){

		var dealPersonChange = "${rc.contextPath}/allot/dealPersonChange";
		var dealCompanyChange = "${rc.contextPath}/allot/dealCompanyChange";
		
		var receivedCompany = $("#receivedCompany option:selected").val().split(",")[0];//选中分公司id
		var receivedPerson = $("#receivedPerson option:selected").val();//选中员工empNo.
		
		var companyNow = $("#compamyid").val();
		
		if(receivedCompany!=companyNow){//跨公司
			if(confirm("您确定要调配当前客户？")){
				$('#allotFrom').attr('action',dealCompanyChange);
				document.getElementById("allotFrom").submit();
			}
		}
		if(receivedCompany==companyNow){//同公司
			if(confirm("您确定要调配当前客户？")){
				$('#allotFrom').attr('action',dealPersonChange);
				document.getElementById("allotFrom").submit();
			}
		}
		
	}
</script>
</head>
<body>
	<div class="page-header">
	
	<div class="container" style="padding-right:0px;padding-left:0px;margin-left:20px;">
			<div style="margin-bottom:30px;padding-bottom:10px; border-bottom:1px dotted #e2e2e2">
				当前位置 》<i class="icon-double-angle-right"></i> 客户管理 》 <i
					class="icon-double-angle-right"></i> 我的工作台
				
				<p style="float: right">姓名： $!{currentUser.ename}</p>
			</div>
        <ul id="myTab" class="nav nav-tabs">
            <li>
                <a href="#summary" data-toggle="tab" onclick="tabclick('1')"><span id="summaryspan" class="badge pull-right badge-danger">0</span>新客户</a>
            </li>
            <li>
                <a href="#region" data-toggle="tab" onclick="tabclick('3')">意向客户</a>
            </li>
            <li>
                <a href="#waitcharge" data-toggle="tab" onclick="tabclick('5')">待续费客户</a>
            </li>
            <li>
                <a href="#protect" data-toggle="tab" onclick="tabclick('12')">保护期客户</a>
            </li>
            <li>
                <a href="#second" data-toggle="tab" onclick="tabclick('8')"><span id="secondspan" class="badge pull-right badge-danger">0</span>二次开发客户</a>
            </li>
        </ul>

        <div id="myTabContent" class="tab-content">
            <div id="summary" class="tab-pane fade in active">
                <table id="summary_table"></table>
            </div>
            <div id="region" class="tab-pane fade">
            
	             <!-- <div id="toolbar" align="center">   自定义查询条件部分，由于工期限制，后期继续完成
	             <label class="control-label col-sm-2" >销售阶段：</label>
				 <select class="btn btn-default">
				 	<option>请选择</option>
				 	<option>需求待确定</option>
				 	<option>需求确定</option>
				 	<option>等待付款</option>
				 </select>
				 
				 <button id="btn_delete" type="button" class="btn btn-default" onclick = "maketable('2')">查询</button>
				 </div> -->
				 
                <table id="region_table">
                </table>
            </div>
            <div id="waitcharge" class="tab-pane fade">
                <table id="waitcharge_table"></table>
            </div>
            <div id="protect" class="tab-pane fade">
                <table id="protect_table"></table>
            </div>
            <div id="second" class="tab-pane fade">
                <table id="second_table"></table>
            </div>
        </div>
    </div>
    
    <!-- 模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	    <div class="modal-dialog">
	        <div class="modal-content">
	            <div class="modal-header">
	                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
	                <h2 class="modal-title" id="myModalLabel">调配申请</h2>
	            </div>
	            
	            <form id="allotFrom"  class="form-horizontal" method="post"	action="${rc.contextPath}/allot/dealPersonChange">
	              <div class="control-group">
				    <label class="control-label">当前分公司：</label>
				    <label class="control-label" id="companyNow"></label>
				  </div>
				  <div class="control-group">
				    
				    <div class="controls">
				    	<label class="control-label" for="inputEmail">接收人：</label>
				        <select id="receivedCompany" name="receivedCompany" onchange="setReceivedPersonShow(this.value);setReceivedPerson(this.value);" class="selectpicker">
                     	 <option value="--">请选择</option>
                		</select>
                		<select id="receivedPerson" name="receivedPerson" class="selectpicker" >
                     	 <option value="--">请选择</option>
                		</select>
				    </div>
				  </div>
				  <div >
				    <label class="control-label" for="inputPassword">调配原因：</label>
				    
				    <textarea id="mixCause" name="mixCause" rows="3"  > </textarea>
				  </div>
				  <div class="modal-footer">
				      <button type="button" class="btn" onclick="checkApplyParam()">确定</button>
				      <button type="button" class="btn btn-default" data-dismiss="modal" onclick="clearSelect()">取消</button>
				  </div>
				  	  <input type="hidden" id="selectedCusId" name="selectedCusId"/>
				  	  <input type="hidden" id="compamyid" name="compamyid"/>
				</form>
	        </div><!-- /.modal-content -->
	    </div><!-- /.modal -->
	</div>	
					
	</div>
	<input id="rootPath" type="text" value="${rc.contextPath}" style="display: none" />
	<input id="customerTypeId" type="text" style="display: none"/>
	
</body>
</html>